Passed
Push — master ( db8da5...c2ef0a )
by Eduardo
02:35
created

$(ꞌ#bwaAnalyserModalCloseButtonYesꞌ).click   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
dl 0
loc 5
rs 10
nop 0
1
/** global: appSettings */
2
var whois = require('../../common/whoiswrapper.js'),
3
  conversions = require('../../common/conversions.js'),
4
  fs = require('fs'),
5
  Papa = require('papaparse'),
6
  dt = require('datatables')(),
7
  bwaFileContents;
8
9
const {
10
  ipcRenderer
11
} = require('electron');
12
13
ipcRenderer.on('bwa:analyser.tablegen', function(event, contents) {
14
  bwaFileContents = contents;
15
  showTable();
16
});
17
18
$('#bwaAnalyserButtonClose').click(function() {
19
  $('#bwaAnalyserModalClose').addClass('is-active');
20
});
21
22
$('#bwaAnalyserModalCloseButtonYes').click(function() {
23
  $('#bwaAnalyser').addClass('is-hidden');
24
  $('#bwaAnalyserModalClose').removeClass('is-active');
25
  $('#bwaEntry').removeClass('is-hidden');
26
});
27
28
$('#bwaAnalyserModalCloseButtonNo').click(function() {
29
  $('#bwaAnalyserModalClose').removeClass('is-active');
30
});
31
32
function showTable() {
33
  var header = {},
34
    body = {};
35
  header.columns = Object.keys(bwaFileContents.data[0]);
36
  console.log(header.columns);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
37
  body.records = bwaFileContents.data;
38
39
  // Generate header column content
40
  header.content = '<tr>\n';
41
  for (column in header.columns) {
0 ignored issues
show
Bug introduced by
The variable column seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.column.
Loading history...
42
    header.content += '\t<th><abbr title="{0}">{1}</abbr></th>\n'.format(header.columns[column], getInitials(header.columns[column]));
43
  }
44
  header.content += '</tr>';
45
46
  $('#bwaAnalyserTableThead').html(header.content);
47
  //console.log(header.content);
48
49
  // Generate record fields
50
  body.content = '';
51
  for (record in body.records) {
0 ignored issues
show
Bug introduced by
The variable record seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.record.
Loading history...
52
    body.content += '<tr>\n';
53
    //console.log(body.content);
54
    //console.log(body.records[record]);
55
56
    for (field in body.records[record]) {
0 ignored issues
show
Bug introduced by
The variable field seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.field.
Loading history...
57
      body.content += '\t<td>{0}</td>\n'.format(body.records[record][field]);
58
    }
59
    body.content += '</tr>\n';
60
  }
61
  //console.log(body.content);
62
  $('#bwaAnalyserTableTbody').html(body.content);
63
  basetable = $('#bwaAnalyserTable').dataTable();
0 ignored issues
show
Bug introduced by
The variable basetable seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.basetable.
Loading history...
64
  //$('#bwaAnalyserTable_paginate > a').addClass('button is-small')
65
66
  $('#bwaFileinputconfirm').addClass('is-hidden');
67
  $('#bwaAnalyser').removeClass('is-hidden');
68
}
69
70
function getInitials(string, threshold = 1) {
71
  initials = string.match(/\b\w/g);
0 ignored issues
show
Bug introduced by
The variable initials seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.initials.
Loading history...
72
73
  (initials.length > threshold) ?
74
    initials = initials.join("").toString() :
75
    initials = string.substring(0, threshold + 1);
76
77
  return initials;
78
}
79